﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model.SystemSetting;
using System.Data;
using System.Data.Entity;

namespace DAL.SystemSetting
{
    public class LoginManagingDal
    {
        private UserInfoDBContext uiDb = new UserInfoDBContext();

        public List<UserInfo> fetchUsersList()
        {
            return uiDb.UsersDb.ToList();
        }

        public int SaveUser(UserInfo user)
        {
            uiDb.UsersDb.Add(user);
            return uiDb.SaveChanges();
        }

        public UserInfo FetchSingleUser(int uid)
        {
            return uiDb.UsersDb.Find(uid);
        }

        public int UpdateUser(UserInfo user)
        {
            uiDb.Entry(user).State = EntityState.Modified;  //需要添加System.Data.Entity程序集，新建的类库里默认不引用
            return uiDb.SaveChanges();
        }

        public int DeleteSingleUser(UserInfo user)
        {
            uiDb.UsersDb.Attach(user);
            uiDb.UsersDb.Remove(user);
            return uiDb.SaveChanges();
        }
    }
}
